//
//  BSPasswordSettingViewController.m
//  SuoSiApp
//
//  Created by zhang on 16/4/15.
//  Copyright © 2016年 Ym. All rights reserved.
//

#import "ViewController.h"
#import "StringResponse.h"
#import "BSPasswordSettingView.h"
#import "BSPasswordSettingViewController.h"

@interface BSPasswordSettingViewController ()
@property (nonatomic, strong) BSPasswordSettingView *passwordSettingView;
@end

@implementation BSPasswordSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:235/255.0 green:236/255.0 blue:237/255.0 alpha:1];
    self.passwordSettingView = [[BSPasswordSettingView alloc]initWithFrame:CGRectMake(0, 0, kScrenWidth, kScrenHeight)];
    [self.passwordSettingView.backBT addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_passwordSettingView];
    
    
    [self.passwordSettingView.saveBT addTarget:self action:@selector(savePassword) forControlEvents:(UIControlEventTouchUpInside)];
    
}
//提交新密码
- (void)savePassword{
    
    NSString *newPassword = self.passwordSettingView.confirmPWTF.text;
    NSString *oldPassword = self.passwordSettingView.originalPWTF.text;
    NSString *confirmPassword = self.passwordSettingView.ynewPWTF.text;
    NSLog( @">> 输入的新密码 %@",newPassword);
    
    if ([newPassword isEqualToString:confirmPassword]) {
        
        if (newPassword.length < 8) {
            [PKRequestManager showAlertView:@"密码必须为8位数字"];
            return;
        }
        
        [PKRequestManager ChangePwdWithnetUrl:NetStr userID:[BSUserSGton userHandle].user_id password:newPassword passwordOld:oldPassword method:POST finish:^(NSData *data) {
            //        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            //        NSLog(@"%@",dic);
            
            StringResponse *strResponseModel = [[StringResponse alloc]init];
            [strResponseModel dealWithData:data];
            if ([strResponseModel.Code isEqualToString:@"0"]) {
                [BSUserSGton userHandle].isLogin = NO;
                ViewController *vc = [[ViewController alloc]init];
                [self.navigationController pushViewController:vc animated:YES];

            }
            
        } error:^(NSError *error) {
            ;
        }];
        

    } else {
        [PKRequestManager showAlertView:@"两次输入密码不同"];
    }
    
    
    /************11111111**************/


    

}
- (void)back{

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
